#include "StdAfx.h"
#include "SeparateConnector.h"


CSeparateConnector::CSeparateConnector(void)
{
}

CSeparateConnector::CSeparateConnector(const CSeparateConnector *pConnector) : CEntityObj(pConnector)
{
	m_PinList = pConnector->GetPinList();
}

CSeparateConnector::CSeparateConnector(CSubSystem *pParent) : CEntityObj(pParent)
{

}

CSeparateConnector::~CSeparateConnector(void)
{
	Clear();
}

bool CSeparateConnector::IsSeparateConnector() const
{
	return true;
}

void CSeparateConnector::Serialize(CArchive & ar)
{
	if (ar.IsStoring())
	{
		int nSize = m_PinList.size();
		ar << nSize;
		for (std::list<CPin *>::iterator iter1=m_PinList.begin(); iter1!=m_PinList.end(); iter1++)
		{
			CPin *pPin = *iter1;
			pPin->Serialize(ar);
		}
	}
	else
	{
		int nSize(0);
		ar >> nSize;
		for (int i=0; i<nSize; i++)
		{
			CPin *pPin = new CPin;
			pPin->Serialize(ar);
			m_PinList.push_back(pPin);
		}
	}

	CEntityObj::Serialize(ar);
}

CObj* CSeparateConnector::Clone() const
{
	return new CSeparateConnector(this);
}

void CSeparateConnector::Clear()
{
	std::list<CPin *>::iterator iter1;
	for (iter1=m_PinList.begin(); iter1!=m_PinList.end(); iter1++)
		delete *iter1;
	m_PinList.clear();

	CEntityObj::Clear();
}

void CSeparateConnector::Transform(const CMatrix transf)
{

}

bool CSeparateConnector::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return true;
}

void CSeparateConnector::CopyDisplayObj(long lSourceLayerId, long lDestLayerId)
{
	CEntityObj::CopyDisplayObj(lSourceLayerId, lDestLayerId);

	std::list<CPin *>::iterator iter;
	for(iter=m_PinList.begin(); iter!=m_PinList.end(); ++iter)
		(*iter)->CopyDisplayObj(lSourceLayerId, lDestLayerId);
}

HTREEITEM CSeparateConnector::InsertToTree(CTreeCtrl *pTreeCtrl, HTREEITEM hParentItem, long lLayerId)
{
	HTREEITEM hConnectorItem=CEntityObj::InsertToTree(pTreeCtrl, hParentItem, lLayerId);
	if(hConnectorItem)
	{
		std::list<CPin *>::iterator iter;
		for(iter=m_PinList.begin(); iter!=m_PinList.end(); ++iter)
		{
			(*iter)->InsertToTree(pTreeCtrl, hConnectorItem, lLayerId);
		}
	}

	return hConnectorItem;
}

CEntityObj * CSeparateConnector::GetEntObjByID(const long lEntObjId)
{
	CEntityObj *pEntObj = NULL;

	std::list<CPin *>::iterator iter1;
	for (iter1=m_PinList.begin(); iter1!=m_PinList.end(); iter1++)
	{
		CPin *pPin = *iter1;
		if (pPin->GetId() == lEntObjId)
			return pPin;
	}

	return pEntObj;
}

std::list<CPin *> CSeparateConnector::GetPinList() const
{
	return m_PinList;
}

void CSeparateConnector::AddPin(CPin *pPin)
{
	m_PinList.push_back(pPin);
}